package org.virbraligo.vboxjavaservice.gui.validator;

import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import org.virbraligo.vboxjavaservice.VBoxJavaService;
import org.virbraligo.vboxjavaservice.gui.AdminFrame;

public class JavaValidator implements Validator {

	public String validate(JComponent comp) {
		String result = null;
		String java = ((JTextField) comp).getText().trim();
		if (java.equals("")) {
			java = "java";
		}
		String cmd = java
				+ " -classpath "
				+ System.getProperty("java.class.path")+" org.virbraligo.vboxjavaservice.gui.validator.JavaVerifier";
		try {
			String success = VBoxJavaService.execute(cmd);
			if (!"success".equals(success)) {
				result = success;
			}
			if (success == null) {
				result = "Java definition, NULL";
			}
		} catch (Exception e) {
			e.printStackTrace();
			result = "Java is not defined correctly. " + e.getMessage();
		}
		return result;
	}
}
